<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Jumper documentation</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>Jumper</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul>
  <li><a href="../examples/annotatedpathing.lua.html">annotatedpathing.lua</a></li>
  <li><a href="../examples/customheuristics.lua.html">customheuristics.lua</a></li>
  <li><a href="../examples/makeclearance.lua.html">makeclearance.lua</a></li>
  <li><strong>simpleexample.lua</strong></li>
</ul>
<h2>Modules</h2>
<ul>
  <li><a href="../modules/core.bheap.html">core.bheap</a></li>
  <li><a href="../modules/core.heuristics.html">core.heuristics</a></li>
  <li><a href="../modules/core.node.html">core.node</a></li>
  <li><a href="../modules/core.path.html">core.path</a></li>
  <li><a href="../modules/grid.html">grid</a></li>
  <li><a href="../modules/pathfinder.html">pathfinder</a></li>
</ul>

</div>

<div id="content">

<h1>Example <code>simpleexample.lua</code></h1>

    <pre>
<span class="comment">--- Very minimal usage example for Jumper
</span>
<span class="comment">-- Set up a collision map
</span><span class="keyword">local</span> map = {
	{<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
}
<span class="comment">-- Value for walkable tiles
</span><span class="keyword">local</span> walkable = <span class="number">0</span>

<span class="comment">-- Library setup
</span><span class="comment">-- Calls the grid class
</span><span class="keyword">local</span> Grid = <span class="global">require</span> (<span class="string">"jumper.grid"</span>)
<span class="comment">-- Calls the pathfinder class
</span><span class="keyword">local</span> Pathfinder = <span class="global">require</span> (<span class="string">"jumper.pathfinder"</span>)

<span class="comment">-- Creates a grid object
</span><span class="keyword">local</span> grid = Grid(map)

<span class="comment">-- Creates a pathfinder object using Jump Point Search algorithm
</span><span class="keyword">local</span> myFinder = Pathfinder(grid, <span class="string">'JPS'</span>, walkable)

<span class="comment">-- Define start and goal locations coordinates
</span><span class="keyword">local</span> startx, starty = <span class="number">1</span>,<span class="number">1</span>
<span class="keyword">local</span> endx, endy = <span class="number">5</span>,<span class="number">1</span>

<span class="comment">-- Calculates the path, and its length
</span><span class="keyword">local</span> path = myFinder:getPath(startx, starty, endx, endy)

<span class="comment">-- Pretty-printing the results
</span><span class="keyword">if</span> path <span class="keyword">then</span>
  <span class="global">print</span>((<span class="string">'Path found! Length: %.2f'</span>):format(path:getLength()))
	<span class="keyword">for</span> node, count <span class="keyword">in</span> path:nodes() <span class="keyword">do</span>
	  <span class="global">print</span>((<span class="string">'Step: %d - x: %d - y: %d'</span>):format(count, node:getX(), node:getY()))
	<span class="keyword">end</span>
<span class="keyword">end</span></pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
